#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
using namespace std;

bool prime(int number) {
    if (number <= 1) return false;
    for(int i = 2; i * i <= number;i++){
        if(number % i ==0)return false;
    }
    return true;
}        

int WordInNubmer(const string& word1,const string& word2,const string& word3){
    vector<string> tableword ={"zero","one","two","three","four","five","six","seven","eight","nine"} ;
    int number1 = find(tableword.begin(), tableword.end(), word1) - tableword.begin();
    int number2 = find(tableword.begin(), tableword.end(), word2) - tableword.begin();
    int number3 = find(tableword.begin(), tableword.end(), word3) - tableword.begin();
    return number1 * 100 + number2 * 10 +number3;
}

int main(){
    string word, word1, word2, word3;
    getline(cin,word);
    istringstream s(word);
    s >> word1 >> word2 >> word3;
    
    if (word1 == "zero" || word2 == "zero" || word3 == "zero") {
        cout << "Wrong input" << endl;
        return 1;
    }
    int number = WordInNubmer(word1,word2,word3);
    if ( number < 100 || number > 999){
        cout << "Wrong input" << endl;
        return 1;
    }
    int miin = number, maax = number;
    while(true){
        if (prime(miin)){
            cout << miin << endl;
            return 0;
        }
        if (prime(maax)){
            cout << maax << endl;
            return 0;
        }
        miin--;
        maax++;
    }
    return 0;
}